package special_tree;

import compiler.CompilerException;

import code.CodeList;
import code.Opcode;
import lexer.Token;
import tree.ClassScope;
import tree.DataType;
import tree.IdentifierScope;
import tree.MethodScope;
import tree.MyTree;
import tree.NamingException;
import tree.Tree;
import tree.Type;
import tree.TypingException;

public class ReturnTree extends MyTree {

	@Deprecated
	Type typ;
	
	public ReturnTree(Token token, Tree expr) {
		super(token, expr);
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#computeType()
	 */
	@Override
	@Deprecated
	public Type computeType() throws TypingException {
		if (getOperands()>0) {
			typ = getOperand(0).computeType();
			return typ;
		}
		typ = new Type(DataType.VOID, "");
		return typ;
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#generateCode(code.CodeList)
	 */
	@Override
	@Deprecated
	public void generateCode(CodeList code) throws CompilerException {
		if (typ.equals(new Type(DataType.VOID, ""))) {
			code.generateCode(Opcode.RETURN);
		}
		else {
			getOperand(0).generateCode(code);
			code.generateCode(Opcode.RETURNVALUE);
		}
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#analyzeNames(tree.IdentifierScope, tree.MethodScope, tree.ClassScope)
	 */
	@Override
	@Deprecated
	public void analyzeNames(IdentifierScope identScope,
			MethodScope methodScope, ClassScope classScope)
			throws NamingException {
		if (getOperands()>0) {
			getOperand(0).analyzeNames(identScope, methodScope, classScope);
		}
	}

}
